package seqlist.oj;

/**
 * @Author: yuisama
 * @Date: 2019/12/6 16:46
 * @Description:删除链表中所有元素-虚拟头节点法
 */
public class Solution203_1 {
    public ListNode removeElements(ListNode head, int val) {
        ListNode dummyHead = new ListNode(val - 1);
        dummyHead.next = head;
        ListNode prev = dummyHead;
        while (prev.next != null) {
            if (prev.next.val == val) {
                prev.next = prev.next.next;
            }else {
                prev = prev.next;
            }
        }
        return dummyHead.next;
    }
}
